home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls024.Z / tls024 / sdce376 / new / bin / sdce.util.c next >
Encoding:
C/C++ Source or Header  |  1992-10-20  |  5.0 KB  |  205 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include <fcntl.h>
  5. #include "sdce.h"
  6.  
  7. main(argc, argv)
  8. int argc;
  9. char *argv[];
  10. {
  11. int    fd;
  12. int    target;
  13. int    type;
  14. int    i;
  15. union sdce_usr_data mydata;
  16. char *ptr;
  17. char    kbd;
  18.  
  19.     target = 0;
  20.     type = 0; /* if type == 0 then hard disk. if type == 5 then CDrom */
  21.     ptr = mydata.fwv;
  22.     if ((fd=open("/dev/host/rsDCE0", O_RDONLY))< 0){
  23.         perror("OPEN: ");
  24.         exit(-1);
  25.     }
  26.     printf("\n\tPlease enter your choice \n");
  27.     printf("\n\tGet Version Number   :  1\n");
  28.     printf("\tGet Cache Statistics :  2\n");
  29.     printf("\tGet Disk Paramters   :  3\n");
  30.     printf("\tFlush the Cache      :  4\n");
  31.     printf("\tSet Controller Params:  5\n");
  32.  
  33.     switch (kbd = getchar()){
  34.  
  35.     case  0x31 :
  36.         /*
  37.          *    Display the hardware version number from the Card. 
  38.          *      This will be the same number displayed by the driver 
  39.          *    boot message.
  40.          */
  41.         strcpy("        ",ptr);
  42.         if (ioctl(fd, FRMWR_VERSION, &mydata) < 0){
  43.             perror("IOCTL: FRMWR_VERSION");
  44.             exit(-1);
  45.         }
  46.         printf("DCE 376 firmware %s\n\n", mydata.fwv);
  47.         break;
  48.  
  49.     case  0x32 :
  50.         /*
  51.          *    Display the cache statistics for the card.
  52.          */
  53.         if (ioctl(fd, CACHE_STATS, &mydata) < 0){
  54.             perror("IOCTL: CACHE_STATS");
  55.             exit(-1);
  56.         }
  57.         printf("\n\t\tDCE 376 Cache Stats\n");
  58.         printf("\tReads\t  Cache Misses on Reads\t     Writes\n");
  59.         printf("\t===========================================\n"); 
  60.         printf("\t%6d            %6d             %6d\n", 
  61.             mydata.cstat[0],mydata.cstat[1],mydata.cstat[2]);
  62.         break;
  63.  
  64.     case 0x33 :
  65.         /* 
  66.          *    Display the drive paramters
  67.          */
  68.         mydata.dtype = type;
  69.         if (ioctl(fd, DRIVE_PARAM, &mydata) < 0){
  70.             perror("IOCTL: DRIVE_PARAM");
  71.             exit(-1);
  72.         }
  73.         i = 0;
  74.         printf("\n\t\tDCE 376 Disk Drive Params\n");
  75.     printf("\tID      Heads     Cylinders      Sec/Trk     Bytes/Sec\n"); 
  76.     printf("\t======================================================\n"); 
  77.         while ( mydata.hd[i].id != -1 ){
  78.             printf("\t %d\t %d\t    %4d\t   %2d\t\t%3d\n",
  79.                 mydata.hd[i].id,mydata.hd[i].hds,
  80.                 mydata.hd[i].cyl,mydata.hd[i].spt,
  81.                 mydata.hd[i].bps);
  82.             i++;
  83.         }
  84.         printf("\n");
  85.         break;
  86.  
  87.     case 0x34 :
  88.         /*
  89.          *    Flush the Host Controller Cache memory.  Much like 
  90.          *    unix sync.
  91.          */
  92.         if (ioctl(fd, CACHE_FLUSH, &mydata) < 0){
  93.             perror("IOCTL: CACHE_FLUSH");
  94.             exit(-1);
  95.         }
  96.         printf("DCE 376 Cache Flushed\n");
  97.         break;
  98.  
  99.     case 0x35 :
  100.         /*
  101.          *    Set the Host Controller Cache Parameters.
  102.          *      Must be root to use this one.
  103.          */
  104.         mydata.cp.parameter = 0x02;/*0x02=8K blocks,0x00=4K blocks   */
  105.  
  106.                    /* flag contolls parameters to set       */
  107.                    /* 0 value for bits means no change      */
  108.         mydata.cp.flag = 0x0e;/* 0x02 = set block size              */
  109.                    /* 0x04 = set write threshold            */
  110.                    /* 0x08 = set inactivity period          */
  111.  
  112.                    /* The number of updated (write) buffers */
  113.                    /* allowed before flushing to disk.  The */
  114.         mydata.cp.wrt_threshold = 26;/*Legal values are 1 - 31      */
  115.                    /* Default is 26.                        */
  116.  
  117.         mydata.cp.inactivity = 2;/* Flush the cache to disk if there*/
  118.                       /* have been no commands in this many   */
  119.                     /* seconds. The legal values are 1 - 15.*/
  120.                     /* Default depending on firmware is     */
  121.                     /* from 1 to 3 seconds. Usually 1 now.  */
  122.  
  123.         if (ioctl(fd, SET_CTRL_PARM, &mydata) < 0){
  124.             perror("IOCTL: SET_CTRL_PARM");
  125.             exit(-1);
  126.         }
  127.         printf("DCE Cache Parameters Set\n");
  128.         break;
  129.  
  130.     default : printf("Bad Option\n");
  131.  
  132.     }
  133. /*
  134.  *    The code below can kill your data on the drive !!!
  135.  
  136.  *
  137.  *    Recalibrate the driver ID.
  138.  *
  139.     mydata.target = 0;  
  140.     if (ioctl(fd, RECAL_DRIVE, &mydata) < 0){
  141.         perror("IOCTL: DRIVE_DIAG");
  142.         exit(-1);
  143.     }
  144.     printf("Recalibration of Drive %d Complete\n",mydata.target);
  145.     sleep(2);
  146.  *
  147.  *    Run Dianostics on drive ID.
  148.  *
  149.     mydata.target = 0;  
  150.     if (ioctl(fd, DRIVE_DIAG, &mydata) < 0){
  151.         perror("IOCTL: DRIVE_DIAG");
  152.         exit(-1);
  153.     }
  154.     printf("Diagnostics for Drive %d Complete\n",mydata.target);
  155.     sleep(2);
  156.  *
  157.  *    Format the drive ID.   This can be a data killer!
  158.  *
  159.     mydata.target = 0;  
  160.     if (ioctl(fd, FORMAT_DRIVE, &mydata) < 0){
  161.         perror("IOCTL: FORMAT_DRIVE");
  162.         exit(-1);
  163.     }
  164.     printf("Format of Drive %d Complete\n",mydata.target);
  165.     *
  166.     */
  167.     close(fd);
  168. }
  169.  
  170. /******************************************************************
  171.  *
  172.  *    FOR DEMO ONLY Don't try these unless you know your drives
  173.  *    have backups or you don't care!  You will have to be root
  174.  *    to run these.
  175.  *
  176. /******************************************************************
  177.  
  178.     if (ioctl(fd, SET_CTRL_PARM, &mydata) < 0){
  179.         perror("IOCTL: SET_CTRL_PARMS");
  180.         exit(-1);
  181.     }
  182.     printf("DCE Cache Paramters Set\n");
  183.  
  184.     mydata.target = 0;  
  185.     if (ioctl(fd, FORMAT_DRIVE, &mydata) < 0){
  186.         perror("IOCTL: FORMAT_DRIVE");
  187.         exit(-1);
  188.     }
  189.     printf("Format of Drive %d Complete\n",target);
  190.  
  191.     mydata.target = 0;  
  192.     if (ioctl(fd, DRIVE_DIAG, &mydata) < 0){
  193.         perror("IOCTL: DRIVE_DIAG");
  194.         exit(-1);
  195.     }
  196.     printf("Diagnostics for Drive %d Complete\n",target);
  197.  
  198.     mydata.target = 0;  
  199.     if (ioctl(fd, RECAL_DRIVE, &mydata) < 0){
  200.         perror("IOCTL: DRIVE_DIAG");
  201.         exit(-1);
  202.     }
  203.     printf("Recalibration of Drive %d Complete\n",target);
  204. */
  205.